<!DOCTYPE HTML>
<html>

<head>
	<meta charset="utf-8">
	<title>编辑地址</title>
	<meta name="keywords" content="KEYWORDS...">
	<meta name="description" content="DESCRIPTION...">
	<meta name="author" content="DeathGhost">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="apple-touch-fullscreen" content="yes">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="format-detection" content="telephone=no">
	<meta name="format-detection" content="address=no">
	<meta name="viewport" content="initial-scale=1, width=device-width, maximum-scale=1, user-scalable=no">
	<link rel="stylesheet" type="text/css" href="../../css/my/cydz/CityPicker.css">

	<style>
	body{
	  background-color: #fcfcfc;
	  height:100%;
	  padding-top:40px;
	}
	.header{
	 width: 100%;height:40px;
	}
	.leftreturn{
	 width:25px;
	 height:25px;
	 margin:7.5px;
	 float: left;
	}
	.formarea li a {
	 line-height: 0.74rem;
	 color: #989898;
	}

	.formarea li {
	 height: 0.8rem;
	 padding: 1% 2%;
	 background: #fff;
	 border-bottom: 1px solid #ccc;
	}
	.formarea li input {
	 line-height: 0.74rem;
	}
	input{
	 border: none;
	 outline: none;
	 font-size: 16px;
	 color: #989898;
	}

	.save{
	 float: right;
	 line-height: 40px;
	 margin-right: 20px;
	 color: #000080
	}

	</style>
</head>

<body style="width: 100%;overflow-x: hidden;">
	<div class="header">
		<a href="cydz.html"><img src="../../image/leftreturn.png" alt="" class="leftreturn"></a>
		<span class="save"  onclick="submit();">保存</span>
	</div>
	<ul class="formarea">
		<li><input id="consignee" name="" type="text" value="用户姓名"onfocus="if (value =='用户姓名'){value =''}" onblur="if (value ==''){value='用户姓名'}"/></li>
		<li>
			<input id="mobile" name="" type="text" value="用户号码"onfocus="if (value =='用户号码'){value =''}" onblur="if (value ==''){value='用户号码'}"/>
			</li>
		<li>
			<label class="lit">所在地区</label>
			<input id="location"  name="" type="text" value="省份城市"onfocus="if (value =='省份城市'){value =''}" onblur="if (value ==''){value='省份城市'}"/>
		</li>
		<li>
			<input id="detailaddress" name="" type="text" value="详细地址"onfocus="if (value =='详细地址'){value =''}" onblur="if (value ==''){value='详细地址'}"/>
		</li>
	</ul>
	<div style="height:1.2rem;"></div>
	<script src="../../css/my/cydz/picker.min.js"></script>
	<script src="../../css/my/cydz/city.js"></script>
	<script type="text/javascript" src="../../script/SHA1.js"></script>
	<script type="text/javascript" src="../../script/api.js"></script>
<script>
apiready=function(){
}

function submit(){

	var consignee = document.getElementById("consignee").value;
	var mobile = document.getElementById("mobile").value;
	var location = document.getElementById("location").value;
	var detailaddress = document.getElementById("detailaddress").value;

	//获取X-APICloud-AppKey值
	var now = Date.now();
	appKey = SHA1("A6032422409194"+"UZ"+"808CF36B-60D4-DC5D-C9F3-FB49F9E1FB44"+"UZ"+now)+"."+now

	api.ajax({
	    url: 'https://d.apicloud.com/mcm/api/address/'+api.pageParam.address_id,
			method: 'POST',
			cache:  false,
			headers:{
				"X-APICloud-AppId": "A6032422409194",
				"X-APICloud-AppKey": appKey
			},
			data:{
				values: {
				 "consignee":consignee,
				"mobile":mobile,
				"location":location,
				"detailaddress":detailaddress,
				"_method":"PUT"
								}
			}
	},function(ret, err){
	    if (ret) {
					var user = $api.getStorage('user');
					for (var i = 0; i < user[0].address.length; i++) {
						if(user[0].address[i].id==api.pageParam.address_id){
							user[0].address[i]=ret;
						}
					}
					$api.setStorage('user', user);


					api.sendEvent({
					    name: 'csdz',
					    extra: {
					        user: user
					    }
					});
					alert('修改成功');
          api.closeWin();
	    } else {
	        alert('数据库连接失败');
	    }
	});

}



</script>

</body>

</html>
